package com.example.pc.myapplication;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btn_activity;
    private TextView tv_activity;
    private EditText et_activity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    public void receiverData(String s){
        tv_activity.append(s);
    }
    private void initView() {
        btn_activity = findViewById(R.id.btn_activity);
        tv_activity = findViewById(R.id.tv_activity);
        et_activity = findViewById(R.id.et_activity);
        btn_activity.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_activity:
                String s = et_activity.getText().toString();
                FragmentManager ft = getSupportFragmentManager();
                Fragment fragment = ft.findFragmentById(R.id.first_fragment);
                if (fragment instanceof  FirstFragment){
                    FirstFragment ff = (FirstFragment) fragment;
                    ff.appendTextView(s);
                }
                break;
        }
    }
}
